// 启动 npm nodemon xxx.js  自动运行修改的文件
// Interstor 迭代器

const set = new Set([11, 22, 33])

const inter = set[Symbol.iterator]()

// console.log(inter.next())
// console.log(inter.next())
// console.log(inter.next())
// console.log(inter.next())

// 实现可迭代结构

const obj = {
  store: ['foo', 'bar', 'baz'],
  [Symbol.iterator]: function () {
    let index = 0
    const self = this
    return {
      next: function () {
        const val = {
          value: self.store[index],
          done: index >= self.store.length
        }
        index++
        return val
      }
    }
  }
}

for (const item of obj) {
  console.log(item)
}

console.log('``````````````````````````````')
const todos = {
  a: ['吃饭', '睡觉', '打豆豆'],
  b: ['语文', '数学', '英语'],
  c: ['电视', '冰箱'],
  [Symbol.iterator]: function () {
    let index = 0
    const self = this
    const arr = [].concat(this.a, this.b, this.c)
    return {
      next: function () {
        const value = {
          value: arr[index],
          done: index++ >= arr.length
        }
        return value
      }
    }
  }
}
for (const item of todos) {
  console.log('todos', item)
}
